package com.cy1;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class StudentTest {
    public static void main(String[] args) {
        Collection<Student> c=new ArrayList<Student>();
        Student s1 = new Student("陈勇", 25);
        Student s2 = new Student("老婆", 25);
        Student s1314 = new Student("一生一世", 10000);
        c.add(s1);
        c.add(s2);
        c.add(s1314);
        Iterator<Student> it = c.iterator();
        while(it.hasNext()){
            Student s = it.next();
            if(s==s1){
                c.add(new Student("帅哥",25));//在调用add方法后，实际修改次数会加一，导致下一次迭代器再调用next方法时会抛出异常，若此时
                //终止JVM，则不会调用下一次的next方法，异常也就不会抛出了，此时add也是添加成功了的
            }
            System.out.println(c);

            /*System.exit(0);*/
        }


    }
}
